﻿using BackEnd;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media.Imaging;

namespace FrontEnd
{
	public class StringToImageConverter : IValueConverter
	{
		private static Dictionary<NodeType, BitmapImage> _iconCache;

		static StringToImageConverter()
		{
			_iconCache = new Dictionary<NodeType, BitmapImage>();
			_iconCache.Add(NodeType.SQLite, new BitmapImage(new Uri("pack://application:,,,/Images/SQLite.png")));
			_iconCache.Add(NodeType.Database, new BitmapImage(new Uri("pack://application:,,,/Images/Database.png")));
			_iconCache.Add(NodeType.AttachedDatabase, new BitmapImage(new Uri("pack://application:,,,/Images/AttachedDatabase.png")));
			_iconCache.Add(NodeType.TableCollection, new BitmapImage(new Uri("pack://application:,,,/Images/TableCollection.png")));
			_iconCache.Add(NodeType.ViewCollection, new BitmapImage(new Uri("pack://application:,,,/Images/ViewCollection.png")));
			_iconCache.Add(NodeType.ColumnCollection, new BitmapImage(new Uri("pack://application:,,,/Images/ColumnCollection.png")));
			_iconCache.Add(NodeType.IndexCollection, new BitmapImage(new Uri("pack://application:,,,/Images/IndexCollection.png")));
			_iconCache.Add(NodeType.TriggerCollection, new BitmapImage(new Uri("pack://application:,,,/Images/TriggerCollection.png")));
			_iconCache.Add(NodeType.Table, new BitmapImage(new Uri("pack://application:,,,/Images/Table.png")));
			_iconCache.Add(NodeType.View, new BitmapImage(new Uri("pack://application:,,,/Images/View.png")));
			_iconCache.Add(NodeType.Column, new BitmapImage(new Uri("pack://application:,,,/Images/Column.png")));
			_iconCache.Add(NodeType.Index, new BitmapImage(new Uri("pack://application:,,,/Images/Index.png")));
			_iconCache.Add(NodeType.Trigger, new BitmapImage(new Uri("pack://application:,,,/Images/Trigger.png")));
		}

		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			try
			{
				return _iconCache[((Node)value).Type];
			}
			catch
			{
				return new BitmapImage();
			}
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			throw new NotImplementedException();
		}
	}
}
